import sqlite3
#连接数据库
conn = sqlite3.connect('book.db')
#创建游标
cursor = conn.cursor()
#创建表
#sql = '''create table if not exists sys_user(
#               id int(11) primary key,
#              name varchar(25),
#               age int(3)
#         )'''
#conn.commit()
#cursor.execute(sql)
#插入数据
#insert_sql = "insert into sys_user(id, name, age) values (?, ?, ?)"
#cursor.execute(insert_sql, (1, "root1",18))
#cursor.execute(insert_sql, (2, "root2",18))
#cursor.execute(insert_sql, (3, "root3",18))
#cursor.execute(insert_sql, (4, "root4",18))
#conn.commit()

#查询数据
select_sql = "select * from sys_user"
#cursor.execute(select_sql)
#for row in cursor:
#    print(row)

#cursor.execute(select_sql)
#resuit = cursor.fetchone()
#resuit = cursor.fetchmany(3)
#result = cursor.fetchall()
#print(result)

#修改数据
update_sql = "update sys_user set name=? where id=?"
cursor.execute(update_sql, ("admin", 1))
conn.commit()

#删除数据
delete_sql = "delete from sys_user where id=?"
cursor.execute(delete_sql,(4,))
conn.commit()

cursor.execute(select_sql)
for row in cursor:
    print(row)